import pyttsx3
import speech_recognition as sr
import pyaudio

friend = pyttsx3.init()
r = sr.Recognizer()

while True:
    with sr.Microphone() as source:
        print("Hello! My name is Jarvis! How can I help you?")
        friend.say("Hello! My name is Jarvis! How can I help you?")
        friend.runAndWait()
        audio = r.listen(source)

        try:
            text = r.recognize_google(audio)
            speech = "You said " + text

            if "dance" in text:
                print("How can I dance?")
                friend.say("How can I dance?")
                friend.runAndWait()

            print(speech)
            friend.say(speech)
            friend.runAndWait()

        except:
            print("Sorry, sir! Couldn't understand what you said.")
            friend.say("Sorry, sir! Couldn't understand what you said.")
            friend.runAndWait()
